package com.fhz.day003.mvvm.fragment;

import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.databinding.DataBindingUtil;
import androidx.databinding.ViewDataBinding;
import androidx.fragment.app.Fragment;

import com.fhz.day003.mvvm.BaseViewModel;

/**
 * 时间:2022/3/22
 *
 * @author msfeng
 * 简述: TODO
 */
public abstract class BaseMVVMFragment<VM extends BaseViewModel, DB extends ViewDataBinding> extends Fragment {

    protected VM mViewModel;
    protected DB binding;

    protected abstract void init();
    protected abstract VM createViewModel();
    protected abstract int getLayoutId();

    @Nullable
    @Override
    public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
       binding = DataBindingUtil.inflate(inflater, getLayoutId(), container, false);
       init();
        return binding.getRoot();
    }

    @Override
    public void onActivityCreated(@Nullable Bundle savedInstanceState) {
        super.onActivityCreated(savedInstanceState);
        mViewModel = createViewModel();
    }
}

